﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace Yuekao.Domain.BaseReposi
{
    public class BaseRepository<T> : IBaseRepository<T> where T : class
    {
        private readonly WorkflowContext db;
        public BaseRepository(WorkflowContext db)
        {
            this.db = db;
        }
        public int Add(T t)
        {
            db.Set<T>().Add(t);
            return db.SaveChanges();
        }

        public IQueryable<T> GetAll()
        {
            return db.Set<T>().AsQueryable();
        }

        public T GetValue(Expression<Func<T, bool>> exp)
        {
            return db.Set<T>().Where(exp).FirstOrDefault();
        }

        public int Update(T t)
        {
            db.Set<T>().Update(t);
            return db.SaveChanges();
        }
    }
}
